package com.dragon.modules.yuegou.service.impl.merchant;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.modules.yuegou.entity.merchant.MerchantGroupEntity;
import com.dragon.modules.yuegou.mapper.merchant.MerchantGroupMapper;
import com.dragon.modules.yuegou.model.merchant.MerchantGroup;
import com.dragon.modules.yuegou.query.merchant.MerchantGroupQuery;
import com.dragon.modules.yuegou.service.merchant.MerchantGroupService;
import com.dragon.modules.yuegou.web.Check;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商户分组用户表 服务实现
 *
 * @author pbuilder generated
 * @date 2019-03-26 11:02:05
 * @version 2.0
 */
@Slf4j
@Service("merMerchantGroupService")
public class MerchantGroupServiceImpl
		extends ServiceImpl<MerchantGroupMapper, MerchantGroupEntity>
		implements MerchantGroupService {

	@Transactional
	@Override
	public void saveMerchantGroup(List<MerchantGroup> dataAccessList,String groupId,String busdId) {
		Check.notNull(groupId,"分组id不能为空");
		Check.notNull(busdId,"商圈id不能为空");
		log.info("保存商户分组分配商户，开始==，分组id={}", groupId);
		//先删除分组关联的商户
		MerchantGroupQuery query = new MerchantGroupQuery();
		query.setGroupId(groupId);
		remove(query.toQueryWrapper());

		//再保存商户分组分配的商户
		for (MerchantGroup merchantGroup : dataAccessList) {
			Check.notNull(merchantGroup.getMerchantId(),"商户id不能为空");
			merchantGroup.setGroupId(groupId);
			merchantGroup.setDel(false);
			merchantGroup.setBusdId(busdId);
			save(merchantGroup);
		}
		log.info("保存商户分组分配商户，保存成功，分组id={}", groupId);
	}

}